/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2022-09-16     chn13935838605       the first version
 */
#ifndef APPLICATIONS_MOTOR_MOTOR_H_
#define APPLICATIONS_MOTOR_MOTOR_H_
#include "System.h"


#define PWM_PERIOD_COUNT     (7199)
#define pwmtim1  htim8
#define pwmtim2  htim1
#define PWM_MAX_PERIOD_COUNT              (6900)

#define SERVO_INIT 1080  //Servo zero point //¶æ»úÁãµã

/* 方向 */
typedef enum
{
  MOTOR_F = 0,
  MOTOR_B,
}motor_dir_t;

typedef enum
{
  MOTOR1 = 0,
  MOTOR2,
  MOTOR3,
}motor_t;




/* CUBEMX SET_COMPARE */
#define SET_MOTOR1_COMPAER1(ChannelPulse)     __HAL_TIM_SET_COMPARE(&pwmtim1,TIM_CHANNEL_1,ChannelPulse)
#define SET_MOTOR1_COMPAER2(ChannelPulse)     __HAL_TIM_SET_COMPARE(&pwmtim2,TIM_CHANNEL_1,ChannelPulse)
#define SET_MOTOR2_COMPAER1(ChannelPulse)     __HAL_TIM_SET_COMPARE(&pwmtim1,TIM_CHANNEL_2,ChannelPulse)
#define SET_MOTOR2_COMPAER2(ChannelPulse)     __HAL_TIM_SET_COMPARE(&pwmtim2,TIM_CHANNEL_2,ChannelPulse)
#define SET_MOTOR3_COMPAER(ChannelPulse)      __HAL_TIM_SET_COMPARE(&pwmtim2,TIM_CHANNEL_3,ChannelPulse)


#define MOTOR1_ENABLE()      HAL_TIM_PWM_Start(&pwmtim1,TIM_CHANNEL_1);HAL_TIM_PWM_Start(&pwmtim2,TIM_CHANNEL_1);
#define MOTOR2_ENABLE()      HAL_TIM_PWM_Start(&pwmtim1,TIM_CHANNEL_2);HAL_TIM_PWM_Start(&pwmtim2,TIM_CHANNEL_2);
#define MOTOR3_ENABLE()      HAL_TIM_PWM_Start(&pwmtim2,TIM_CHANNEL_3);


#define MOTOR1_DISABLE()     HAL_TIM_PWM_Stop(&pwmtim1,TIM_CHANNEL_1);HAL_TIM_PWM_Stop(&pwmtim2,TIM_CHANNEL_1);
#define MOTOR2_DISABLE()     HAL_TIM_PWM_Stop(&pwmtim1,TIM_CHANNEL_2);HAL_TIM_PWM_Stop(&pwmtim2,TIM_CHANNEL_2);
#define MOTOR3_DISABLE()     HAL_TIM_PWM_Stop(&pwmtim2,TIM_CHANNEL_3);

#if 0
/* 方向GPIO */
#define MOTOR1_IN_SET         HAL_GPIO_WritePin(MOTOR1_IN_GPIO_Port, MOTOR1_IN_Pin, GPIO_PIN_SET)
#define MOTOR1_IN_RESET       HAL_GPIO_WritePin(MOTOR1_IN_GPIO_Port, MOTOR1_IN_Pin, GPIO_PIN_RESET)

#define MOTOR2_IN_SET         HAL_GPIO_WritePin(MOTOR2_IN_GPIO_Port, MOTOR2_IN_Pin, GPIO_PIN_SET)
#define MOTOR2_IN_RESET       HAL_GPIO_WritePin(MOTOR2_IN_GPIO_Port,MOTOR2_IN_Pin, GPIO_PIN_RESET)

#endif



extern void set_motor_enable(void);
extern void set_motor_disable(void);

extern void MotorOutput(int Motor1Pwm,int Motor2Pwm,int Motor3Pwm);


#endif /* APPLICATIONS_MOTOR_MOTOR_H_ */
